package com.saihai.jiankang;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class testFormget {
    public static void main(String[] args) {
        String url = "http://172.0.10.161:9666/supplies/baseUse/list"; // 替换为实际的API地址
        String token = "1F82F749F10622B8424C075169FF94EC"; // 替换为实际的Token
//        HttpUtils.sendGet(url);

        // 创建HttpClient实例
        CloseableHttpClient httpClient = HttpClients.createDefault();

        try {
            // 创建HttpGet实例，并设置URL和Token
            HttpGet httpGet = new HttpGet(url);
            httpGet.setHeader("Authorization", "Bearer " + token);
            httpGet.setHeader("Authorization","application/json");
            httpGet.setHeader("Accept","*/*");
            httpGet.setHeader("Cookie","JSESSIONID=1F82F749F10622B8424C075169FF94EC");
            // 执行请求并获取响应
            CloseableHttpResponse response = httpClient.execute(httpGet);

            // 从响应中提取内容
            String responseBody = EntityUtils.toString(response.getEntity());
            JSONObject jsonObject = JSON.parseObject(responseBody);
            JSONArray jsonArray = jsonObject.getJSONArray("data");
//            List<YourDataClass> entityList = JSON.parseArray(jsonArray.toJSONString(), YourDataClass.class);
            List<Object> list = new ArrayList<>();
            for (int i = 0; i < jsonArray.size(); i++) {
                list.add(jsonArray.get(i));
            }
            List<YourDataClass> list1 = jsonArray.toJavaList(YourDataClass.class);
            System.err.println(list1.get(0).getCreateById());
            // 输出响应内容

            // 关闭响应
            response.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                httpClient.close(); // 关闭HttpClient实例
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }


    class YourDataClass {
        // 添加与 JSON 结构对应的字段和相应的 getter 和 setter 方法
        private String createById;
        private String createByName;
        private String createDateTime;
        private String lastModifiedById;
        private String lastModifiedByName;
        private String lastModifiedDateTime;
        private String useId;
        private String name;
        private String type;
        private String syncId;
        private String syncTypeId;
        private String syncTypeName;
        private String remark;
        private String status;
        private String orgId;
        private String orgName;

        public YourDataClass(String key, String string) {
        }

        // Getter 和 Setter 方法
        public String getCreateById() {
            return createById;
        }

        public void setCreateById(String createById) {
            this.createById = createById;
        }

        public String getCreateByName() {
            return createByName;
        }

        public void setCreateByName(String createByName) {
            this.createByName = createByName;
        }

        public String getCreateDateTime() {
            return createDateTime;
        }

        public void setCreateDateTime(String createDateTime) {
            this.createDateTime = createDateTime;
        }

        public String getLastModifiedById() {
            return lastModifiedById;
        }

        public void setLastModifiedById(String lastModifiedById) {
            this.lastModifiedById = lastModifiedById;
        }

        public String getLastModifiedByName() {
            return lastModifiedByName;
        }

        public void setLastModifiedByName(String lastModifiedByName) {
            this.lastModifiedByName = lastModifiedByName;
        }

        public String getLastModifiedDateTime() {
            return lastModifiedDateTime;
        }

        public void setLastModifiedDateTime(String lastModifiedDateTime) {
            this.lastModifiedDateTime = lastModifiedDateTime;
        }

        public String getUseId() {
            return useId;
        }

        public void setUseId(String useId) {
            this.useId = useId;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public String getSyncId() {
            return syncId;
        }

        public void setSyncId(String syncId) {
            this.syncId = syncId;
        }

        public String getSyncTypeId() {
            return syncTypeId;
        }

        public void setSyncTypeId(String syncTypeId) {
            this.syncTypeId = syncTypeId;
        }

        public String getSyncTypeName() {
            return syncTypeName;
        }

        public void setSyncTypeName(String syncTypeName) {
            this.syncTypeName = syncTypeName;
        }

        public String getRemark() {
            return remark;
        }

        public void setRemark(String remark) {
            this.remark = remark;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public String getOrgId() {
            return orgId;
        }

        public void setOrgId(String orgId) {
            this.orgId = orgId;
        }

        public String getOrgName() {
            return orgName;
        }

        public void setOrgName(String orgName) {
            this.orgName = orgName;
        }

        // 其他字段的 getter 和 setter 方法类似
    }
}
